package com.prince.bean;

import java.io.Serializable;

@SuppressWarnings({ "rawtypes", "unchecked" })
public final class Response<T> implements Serializable {
    private static final long serialVersionUID = 3727205004706510648L;
    public static final Integer OK = Integer.valueOf(1);
    public static final Integer ERR = Integer.valueOf(0);
    private Integer status;
    private String err;
    private T data;

    public Response() {
    }

	public static <T> Response<T> ok() {
		Response r = new Response();
        r.status = OK;
        return r;
    }

    public static <T> Response<T> ok(Object data) {
        Response r = new Response();
        r.status = OK;
        r.data = data;
        return r;
    }

    public static <T> Response<T> notOk(Object data) {
        Response r = new Response();
        r.status = ERR;
        r.data = data;
        return r;
    }
    
    public static <T> Response<T> notOk(String err) {
        Response r = new Response();
        r.status = ERR;
        r.err = err;
        return r;
    }

    public static <T> Response<T> notOk(Integer status, String err) {
        Response r = new Response();
        r.status = status;
        r.err = err;
        return r;
    }

    public Boolean isSuccess() {
        return Boolean.valueOf(this.status == OK);
    }

    public Integer getStatus() {
        return this.status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getErr() {
        return this.err;
    }

    public void setErr(String err) {
        this.err = err;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.status = OK;
        this.data = data;
    }

    public String toString() {
        return "Response{status=" + this.status + ", err=\'" + this.err + '\'' + ", data=" + this.data + '}';
    }
}